using System;
using BRozklad.DBLib.DataModel;

namespace BRozklad.RozkladLib
{
    public class CSVDrawing : IDrawing
    {
        public string Draw()
        {
            ReaderFullResult reader = new ReaderFullResult();
            Array fullResult = reader.readFullResult();
            string res = "";
            for (int i = 0; i < fullResult.GetLength(0); i++)
            {
                for (int j = 0; j < fullResult.GetLength(1); j++)
                {
                    if (fullResult.GetValue(i, j) != null)
                    {

                        if (fullResult.GetValue(i, j).GetType().ToString() == "System.String")
                        {
                            res += fullResult.GetValue(i, j).ToString();
                        }
                        else
                        {
                            if (i > 0 && fullResult.GetValue(i - 1, j) != null && fullResult.GetValue(i, j).ToString() == fullResult.GetValue(i - 1, j).ToString())
                            {
                            }
                            else
                            {
                                DrawingDataRow row = reader.getInfoForPair((int)(fullResult.GetValue(i, j)));
                                if (row != null)
                                    res += getInfo(row);
                            }
                        }
                    }
                    res += ";";
                }
                res += "\n";
            }
            return res;
        }
        string getInfo(DrawingDataRow row)
        {
            string res = "";
            res += row.subjectSubject + " " + row.teacherName + " " + row.auditoriasName;
            return res;
        }
    }

 
}
